﻿namespace AuSys.Services.App.UserInfo.Bases
{
    public abstract class HttpUserClaimReader(
        IHttpContextAccessor httpContextAccessor)
    {
        protected int ReadClaimAsInt(string claimName)
        {
            var ctx = httpContextAccessor.HttpContext;
            if (ctx is null)
                return 0;
            var idClaim = ctx.User.Claims.FirstOrDefault(x
                => x.Type == claimName);
            if (idClaim is null)
                return 0;
            else
            {
                if (int.TryParse(idClaim.Value, out int id))
                    return id;
            }
            return 0;
        }
    }
}
